{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-01T10:14:03.106535Z",
     "start_time": "2020-08-01T10:14:03.101548Z"
    }
   },
   "outputs": [],
   "source": [
    "from collections import defaultdict\n",
    "def borda_count(input_list,N):\n",
    "    score=defaultdict(int)\n",
    "    for i in range(len(input_list)):\n",
    "        for j in range(N):\n",
    "            score[input_list[i][j]]+=N-j\n",
    "    return sorted(score.items(), key=lambda d:d[1], reverse = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-08-01T10:14:07.985643Z",
     "start_time": "2020-08-01T10:14:07.979688Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('a', 12), ('b', 11), ('x', 8), ('z', 8), ('y', 6)]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input_list=[\n",
    "    ['x','a','b','z','y'],\n",
    "    ['a','y','b','z','x'],\n",
    "    ['b','z','a','x','y']\n",
    "]\n",
    "borda_count(input_list,5)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
